﻿using System.Collections.Generic;
using Dsl.Ped.AddIn.Beeps.Helpers;
using Dsl.Ped.AddIn.Beeps.Projections.LinkedListProjection;
using Dsl.Ped.AddIn.Java.Resources;
using Dsl.Ped.Framework.Common;
using Dsl.Ped.Framework.Projections;

namespace Dsl.Ped.AddIn.Beeps.Generated
{
    /// <summary>
    /// This is the class that enhances the <see cref="Beeps"/> class
    /// provided in the model of projections, these are organized into containers
    /// </summary>
    public partial class Beeps : IProjective
    {
        /// <summary>
        /// Gets the collection of <see cref="IProjectionContainer"/> objects
        /// </summary>
        /// <returns>A collection of <see cref="IProjectionContainer"/> objects belonging 
        /// to the <see cref="Beeps"/> class</returns>
        public List<IProjectionContainer> GetProjectionContainers()
        {
            return new List<IProjectionContainer>()
                {
                    new ProjectionContainer("Linked List")
                        .RegisterProjection("LinkedList", new LinkedListProjection(this, "Beep")),

                    new ProjectionContainer("Vertical Projection", CollectionProjectionFactory.GetVerticalProjection(this, () => Beep, 
                        vp => { vp.RemoveItem = bObject => { Beep.Remove(bObject as BeepsBeep); }; })),

                    new ProjectionContainer("Plain Text") { ForceRefresh = true }
                        .RegisterProjection("PlainText", TextProjectionFactory.GetSyntaxHighlighterProjection(
                            this, 
                            ConvertMe, 
                            sh => { 
                                sh.KeyWords = BeepsResources.GetKeyWords();
                                sh.KeyWordsDelimiter = BeepsResources.KeyWordsDelimiter;
                            })) 
                };
        }

        /// <summary>
        /// Converts the object into its plain text representation.
        /// This method is required by the SyntaxHighlighterProjection.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private string ConvertMe(object obj)
        {
            int tabsCount = 3;
            var tabSpace = new string(' ', tabsCount);

            var javaClass = (Beeps)obj;
            var strClass = BeepsHelper.ToPlainText(javaClass);

            var result = strClass.Replace("\t", tabSpace);
            return result;
        }
    }
}
 